//
//  SpeechSettingViewController.m
//  HeWeiZhiNeng
//
//  Created by 林建 on 17/12/6.
//  Copyright © 2017年 YanCeyMichael.github.io. All rights reserved.
//

#import "SpeechSettingViewController.h"
#import "SpeechSettingCell.h"
#import "SpeechHeadView.h"
@interface SpeechSettingViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong)UICollectionView *collectionV;
@property (nonatomic, strong)NSMutableArray *dataArr;
@end

@implementation SpeechSettingViewController
-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSMutableArray arrayWithObjects:@{@"title":@"解锁",@"img":@"yuyin_jiesuo"}, @{@"title":@"锁车",@"img":@"yuyin_suoche"}, @{@"title":@"启动",@"img":@"yuyin_qidon"}, @{@"title":@"熄火",@"img":@"yuyin_xihuo"}, @{@"title":@"开窗",@"img":@"yuyin_kaichuang"}, @{@"title":@"关窗",@"img":@"yuyin_guanchuang"}, @{@"title":@"通风",@"img":@"yuyin_tongfeng"}, nil];
    }
    return _dataArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = Color.back;
    [self setUpNavigation];
    [self.view addSubview:self.collectionV];
    // Do any additional setup after loading the view.
}

-(void)setUpNavigation{
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = Color.theme;
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 addTarget:self action:@selector(leftBar1Clicked) forControlEvents:UIControlEventTouchUpInside];
    [btn1 setImage:[UIImage imageNamed:@"zhuce_fanhui"] forState:UIControlStateNormal];
    [btn1 sizeToFit];
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithCustomView:btn1];
    self.navigationItem.leftBarButtonItem = item1;
    UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 62, 20)];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"语音设置";
    titleLabel.textColor = Color.fullBtnTitle;
    titleLabel.font = Common_Font(18);
    self.navigationItem.titleView = titleLabel ;
}

-(void)leftBar1Clicked{
    [self.rt_navigationController popViewControllerAnimated:YES];
}

#pragma mark ----- 创建collectionView -----
-(UICollectionView *)collectionV{
    if (!_collectionV) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        _collectionV = [[UICollectionView alloc]initWithFrame:CGRectMake(15, 0, kScreenW-30,    kScreenH) collectionViewLayout:layout];
        layout.itemSize = CGSizeMake(170, 100);
        layout.minimumLineSpacing = 25;
        layout.minimumInteritemSpacing = kScreenW-340-30;
        layout.headerReferenceSize = CGSizeMake(kScreenW, 54);
        _collectionV.delegate = self;
        _collectionV.dataSource = self;
        _collectionV.backgroundColor = Color.back;
        _collectionV.showsVerticalScrollIndicator = NO;
        [_collectionV registerClass:[SpeechSettingCell class] forCellWithReuseIdentifier:@"speechCell"];
        [_collectionV registerClass:[SpeechHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"speechHead"];
    }
    return _collectionV;
}

#pragma mark ----- collectionView协议方法 -----
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArr.count;
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = self.dataArr[indexPath.row];
    SpeechSettingCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"speechCell" forIndexPath:indexPath];
    cell.titleLabel.text = dic[@"title"];
    cell.productView.image = [UIImage imageNamed:dic[@"img"]];
    return cell;
}

- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if (kind == UICollectionElementKindSectionHeader)
    {
        SpeechHeadView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"speechHead" forIndexPath:indexPath];
        return headerView;
    }
    return nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
